package com.example.class_manage.Controller;


import com.example.class_manage.Entity.User;
import com.example.class_manage.Mapper.Usermapper;
import com.example.class_manage.Util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/")
@Slf4j
@Api(tags = "老师管理接口")
public class Teacher_Controller {
    @Autowired
    Usermapper usermapper;

    @ApiOperation("增加助教")
    @RequestMapping(value = "/addzhujiao", method = {RequestMethod.POST})
    public JsonData addzhujiao(@RequestBody User u1) {
        Integer statu = 0;

        statu = usermapper.addUser(u1);

        return statu == 1 ? JsonData.buildSuccess("插入成功") : JsonData.buildError("插入失败");
    }

    @ApiOperation("老师更改姓名")
    @PostMapping("/updatetname")
    public JsonData updatetname(@RequestParam("id") int id, @RequestParam("name") String name) {
        Integer statu = 0;
        statu = usermapper.updatetname(id, name);
        return statu != 0 ? JsonData.buildSuccess("更改成功") : JsonData.buildError("更改失败");

    }

    @ApiOperation("老师更改年级")
    @PostMapping("/updategrade")
    public JsonData updategrade(@RequestParam("id") int id, @RequestParam("grade") int grade) {
        Integer statu = 0;

        statu = usermapper.updategrade(id, grade);
        return statu != 0 ? JsonData.buildSuccess("更改成功") : JsonData.buildError("更改失败");
    }

    @ApiOperation("设置学生是批阅人")
    @PostMapping("/updatepi")
    public JsonData updatepi(@RequestParam("id") int id, @RequestParam("iszhujiao") int iszhujiao) {
        Integer statu = 0;
        statu = usermapper.updateUser(id, iszhujiao);
        return statu != 0 ? JsonData.buildSuccess("设置成功") : JsonData.buildError("设置失败");

    }

    @ApiOperation("老师更改班级")
    @PostMapping("/updatetgrade")
    public JsonData updatetgrade(@RequestParam("id") int id, @RequestParam("sclass") int sclass) {
        Integer statu = 0;

        statu = usermapper.updategrade(id, sclass);
        return statu != 0 ? JsonData.buildSuccess("更改成功") : JsonData.buildError("更改失败");
    }
}
